<template>
  <div class="app-container">
    <div class="title"><i class="el-icon-coin"></i>用户协议</div>
    <el-table
      :data="tableData"
      v-loading="loadList"
      header-align="center"
      element-loading-text="拼命加载中..."
      style="width: 100%"
      border
    >
      <el-table-column prop="msg" label="隐私政策内容"></el-table-column>

      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button size="mini" @click="dialogShow(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="修改隐私政策" :visible.sync="dialogVisible" width="30%">
      <el-input
        type="textarea"
        :autosize="{ minRows: 12, maxRows: 24 }"
        placeholder="请输入隐私政策"
        v-model.trim="item.msg"
      ></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="edit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
    
    <script>
import { historyList, edit } from "./api/index";
export default {
  data() {
    return {
      item: {},
      id: "",
      remark: "",
      dialogVisible: false,
      currentPage: 1,
      total: 0,
      pager: 1,
      pageSize: 10,
      loadList: true,
      tableData: [],
    };
  },
  created() {
    this.refresh_data();
  },
  methods: {
    // 列表
    refresh_data() {
      historyList()
        .then((data) => {
          console.log(data, "=====");
          if (data.code === 1) {
            this.tableData = [{ msg: data.data }];
          } else {
            this.$message.error(data.msg);
          }
          this.loadList = false;
        })
        .catch((err) => {
          console.log(err);
          this.loadList = false;
        });
    },

    dialogShow(item) {
      this.item = item;
      this.dialogVisible = !this.dialogVisible;
    },
    // 修改协议
    async edit() {
      this.loadList = !this.loadList;
      const res = await edit(this.item.msg);
      if (res.code === 1) {
        this.refresh_data();
        this.dialogVisible = !this.dialogVisible;
      } else {
        this.loadList = !this.loadList;
        this.$message.error(res.msg);
      }
    },
  },
};
</script>
    
    <style scoped>
</style>
    